package com.dx.architectureddd.common.event.impl;

import com.dx.architectureddd.common.event.DomainEvent;
import com.dx.architectureddd.common.event.DomainEventPublisher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 领域事件发布者——spring event实现
 *
 * @author xin.deng
 * @date 2023/09/24
 */
@Service
@Slf4j
public class DomainSpringEventPublisher implements DomainEventPublisher {

    @Resource
    private ApplicationEventPublisher eventPublisher;

    @Override
    public void publishEvent(DomainEvent domainEvent) {
        log.info("发布领域事件：{}", domainEvent);
        eventPublisher.publishEvent(domainEvent);
    }
}
